package com.baoyang.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Value("${smallprogram.imgurl}")
    private String imgurl;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 确保路径以斜杠结尾，并处理不同操作系统的路径分隔符
        String filePath = imgurl.endsWith("/") ? imgurl : imgurl + "/";
        log.info("配置静态资源映射: /file/** -> file:{}", filePath);
        registry.addResourceHandler("/file/**").addResourceLocations("file:" + filePath);
    }

}
